/**
 * 创建用于 ajax 的 request
 * @return
 */
function createRequest(){
    var request = false;
    if (window.ActiveXObject){
        try {
            request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e){
            try {
                request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch(ee){
                request = false;
            }
        }
    } else {
        try {
            request = new XMLHttpRequest();
        } catch (e){
            request = false;
        }
    }
    return request;
}
/**
 * 通过 ajax 提交数据
 * @param url
 * @param params
 * @return
 */
function send2Server(url,params){
    var request = createRequest();
    request.open("POST",url,false);
    request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    request.send(params);    
}
/**
 * 保存数据
 * @return
 */
function saveData(){
	var json = '[';	
	var row = 0;
	while(true){
	    var id = document.getElementById("id" + "_" + row);
	    var name = document.getElementById("name" + "_" + row);
	    if (id == undefined){
	        break;	        
	    }
	    var obj = '{"id":"' + id.value + '","name":"' + name.value + '"}';
	    if (row > 0){
	        json += ',';
		}
	    json += obj;  
	    row++; 
	}
	json += ']'
    var url = webPath + "/InfoServlet";
	var param = "jsonData=" + json;
	// 保存数据
	send2Server(url,param);
	// 
	alert("保存成功");
}